﻿namespace BankExercise
{
    using System;

    public abstract class Account : IDepositable
    {
        private Customer accCustomer;
        private decimal balance;
        protected decimal interestRatePerMonth;

        internal Customer AccCustomer
        {
            get
            {
                return this.accCustomer;
            }

            set
            {
                this.accCustomer = value;
            }
        }

        internal decimal Balance
        {
            get
            {
                return this.balance;
            }

            private set
            {
                this.balance = value;
            }
        }

        internal decimal InterestRatePerMonth
        {
            get
            {
                return this.interestRatePerMonth;
            }
        
            set
            {
                if (value <= 0)
                {
                    throw new ArgumentOutOfRangeException("No way you can set such a value for interest index");
                }
                else
                {
                    this.interestRatePerMonth = value;
                }
            }
        }

        public virtual void Deposit(decimal sumToDeposit)
        {
            if (sumToDeposit <= 0)
            {
                throw new InvalidOperationException("What are you doing? You cannot deposit a negative (or zero) value!");
            }
            else
            {
                this.Balance += sumToDeposit;
            }
        }

        internal virtual void WithDraw(decimal sumToWithDraw)
        {
            if (sumToWithDraw <= 0)
            {
                throw new InvalidOperationException("You cannot with draw a negative (or zero) value!");
            }
            else
            {
                this.Balance -= sumToWithDraw;
            }
	    }

        internal abstract decimal CalculateInterest(int periodInMonths);
    }
}